home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 21 code / Custom GX Printer Drivers / CustomWriter GX 1.0.1 / OldApp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  5.4 KB  |  182 lines  |  [TEXT/MPS ]

  1. /*
  2.     FILENAME
  3.         OldApp.c
  4.  
  5.     DESCRIPTION
  6.         Contains code for our old-application message overrides.
  7.  
  8.     COPYRIGHT
  9.         Copyright © 1995 Apple Computer, Inc.
  10.         All rights reserved.
  11.     
  12.     Modification history
  13.         05/03/95 - Dave Hersey -    Version 1.0.1 to fix some minor bugs in
  14.                                     CustomBufferingAndIO.c.
  15.  
  16.         01/14/95 - Dave Hersey -    Created from the shell of a hollowed-out
  17.                                     ImageWriter driver.
  18.  
  19.     NOTE: Relevant goodies are listed in MPW's "Mark" menu.
  20.  
  21. */
  22.  
  23. #include "CommonDefines.h"
  24.  
  25.  
  26. /*    -----------------------------------------------------------------------
  27.  
  28.     SD_ConvertPrintRecordTo is an override of gxConvertPrintRecordTo.  It
  29.     takes a print record in old style (driver specific) format, and converts
  30.     it to the format of gxUniversalPrintRecordHdl.  Since we don't have an
  31.     "old-style" format we need to support, there's not much we need to do
  32.     here.
  33.  
  34.     -----------------------------------------------------------------------    */
  35.  
  36. OSErr SD_ConvertPrintRecordTo(THPrint hoPrint)
  37. {
  38.     TPPrint                        poPrint;            // pointer to old style print record
  39.     gxUniversalPrintRecordHdl    huPrint = hoPrint;    // handle to universal print record
  40.     gxUniversalPrintRecordPtr    puPrint;            // pointer to universal print record
  41.     short                        wDev;                // cached wDev
  42.  
  43.     puPrint = *huPrint;
  44.     poPrint = *hoPrint;
  45.  
  46.     // We always print at our best resolution, and autofeed at 100% scaling.
  47.  
  48.     puPrint->qualityMode = gxBestQuality;
  49.     puPrint->feed =    true;
  50.     puPrint->reduction = 100;
  51.  
  52.     // Save our orientation and copies settings.
  53.     wDev = poPrint->prStl.wDev;
  54.     puPrint->orientation = (wDev & kPortrait)?    gxPortraitOrientation: gxLandscapeOrientation;
  55.     puPrint->actualCopies =    poPrint->prJob.iCopies;
  56.     puPrint->options = 0;
  57.         
  58.     return noErr;
  59. }
  60.  
  61.  
  62. /*    -----------------------------------------------------------------------
  63.  
  64.     SD_ConvertPrintRecordFrom is an override for gxConvertPrintRecordFrom.
  65.     It takes a print record in universal format and converts it to old
  66.     style (driver specific) format.  Since we don't have an "old-style"
  67.     format we need to support, there's not much we need to do here.
  68.  
  69.     -----------------------------------------------------------------------    */
  70.  
  71. OSErr SD_ConvertPrintRecordFrom(gxUniversalPrintRecordHdl huPrint)
  72. {
  73.     gxUniversalPrintRecordPtr    puPrint;            // pointer to universal print record
  74.     THPrint                        hoPrint = huPrint;    // handle to old style print record
  75.     TPPrint                        poPrint;            // pointer to old style print record
  76.     short                        wDev;                // workspace to create our wDev value
  77.  
  78.     // Cache pointers for size and speed
  79.     puPrint = *huPrint;
  80.     poPrint = *hoPrint;
  81.  
  82.     // Convert various fields of our print record, starting with the wDev.
  83.     
  84.     // This is our base wDev value-- note I was bad and didn't register this
  85.     // with DEVSUPPORT.  You should.
  86.  
  87.     wDev = kDriverWDev;
  88.     
  89.     if (puPrint->orientation == gxPortraitOrientation)
  90.         wDev |= kPortrait;
  91.  
  92.     poPrint->prStl.wDev            = wDev;
  93.     poPrint->iPrVersion            = kPrintRecordVers;
  94.     poPrint->prInfo.iDev        = 0;
  95.     poPrint->prInfoPT.iDev         = 0;
  96.     poPrint->prStl.bPort         = 0;
  97.     poPrint->prStl.feed         = false;
  98.     poPrint->prJob.iCopies        = puPrint->actualCopies;
  99.     poPrint->prJob.bJDocLoop    = 1;
  100.     
  101.     // This routine is so studly, there can be no errors
  102.     return noErr;    
  103. }
  104.  
  105.  
  106. /*    -----------------------------------------------------------------------
  107.  
  108.     SD_PrValidate is an override of gxPrValidate.  It validates the current
  109.     print record.  It's fairly simplistic--if the wDev or versions don't
  110.     match ours, we call PrintDefault.  Otherwise, we call UpdatePrintRecord
  111.     to allow the driver to sanity check any internal fields.
  112.  
  113.     -----------------------------------------------------------------------    */
  114.  
  115. OSErr SD_PrValidate(THPrint hPrint,         // old style print record
  116.                     Boolean *wasChanged)    // was the print record changed?
  117. {
  118.     unsigned short    wDev;
  119.     Boolean            recordIsInvalid = true;            
  120.     OSErr            anErr = noErr;
  121.  
  122.     // Check the wDev.  The upper byte must be equal to our wDev
  123.         
  124.     wDev = (*hPrint)->prStl.wDev;    
  125.     wDev >>= 8;                        // Get just the device ID
  126.  
  127.     // If the device id is equal to ours, check the version number of the print record.
  128.     // Only if that is also equal to the current version, will we return false (valid).
  129.         
  130.     if ((wDev == (kDriverWDev >> 8)) && ((((*hPrint)->iPrVersion) == kPrintRecordVers)))
  131.         recordIsInvalid = false;
  132.  
  133.     // If the print record is not valid, then call PrintDefault so
  134.     // that QuickDraw GX loads our default print record from 'PREC' 0.
  135.     // Otherwise, do the final sanity check/reset of our print record.
  136.         
  137.     if (recordIsInvalid)
  138.         PrintDefault(hPrint);
  139.     else
  140.         anErr = UpdatePrintRecord(hPrint);
  141.         
  142.     *wasChanged = recordIsInvalid;
  143.     return (anErr);
  144. }
  145.  
  146.  
  147. /*    -----------------------------------------------------------------------
  148.  
  149.     UpdatePrintRecord is called by SD_PrValidate.  It simply does a sanity
  150.     check (and reset) of the volatile fields of our old style print records.
  151.  
  152.     -----------------------------------------------------------------------    */
  153.  
  154. OSErr UpdatePrintRecord(THPrint hPrint)
  155. {
  156.     OSErr                        anErr;
  157.     gxUniversalPrintRecordHdl     huPrint = hPrint;
  158.     gxUniversalPrintRecordPtr     puPrint;
  159.  
  160.     // Convert the print record to universal format.  If there are
  161.     // no errors, store the resolution, and convert the print
  162.     // record back to non-universal format.
  163.  
  164.     anErr = SD_ConvertPrintRecordTo(hPrint);
  165.  
  166.     if (anErr == noErr)
  167.     {
  168.         puPrint = *huPrint;
  169.  
  170.         // Default the app & device resolutions
  171.         puPrint->devVRes =
  172.         puPrint->devHRes =
  173.         puPrint->appVRes =
  174.         puPrint->appHRes = 72;
  175.         
  176.         // Convert back to non-universal format
  177.         anErr = SD_ConvertPrintRecordFrom((gxUniversalPrintRecordHdl) hPrint);
  178.     }
  179.         
  180.     return anErr;
  181. }
  182.